$(function () {
  init();
})
// 初始化
function init(){
    // var id = getParam("id");
    // 确定
    var ajax = new $ax("/user/queryToken", function (data) {
        // 成功
        if (data.status == "true") {

            var users = data.user;
			
			$("#userName").val(users.userName);
			
			$("#gender").val(users.gender);
			$("#birthday").val(formatDateTimeYMDHM(users.birthday));
			$("#email").val(users.email);
			$("#phone").val(users.phone);
			$("#landline").val(users.landline);
			$("#depa").val(users.depa);
			$("#post").val(users.post);
			$("#organization").val(users.organization);
			$("#autograph").val(users.autograph);
			


        } else {
            alert("查看失败");
        }

    }, function (data) {
        // 失败
        alert("访问失败");
        errorAjax();
        alert("查看失败");
    });

    ajax.setToken(cookie.get("token"));
    // ajax.set("id", id);
    ajax.start();
}

function submit2(){
    var id = getParam("id");
    var userName = $("#userName").val();
    if(userName == ""){
        alert("用户名不能为空");
        return;
    }
    var password = $("#password").val();
    if(password == ""){
        alert("密码不能为空");
        return;
    }
    var gender = $("#gender").val();
    if(gender == ""){
        alert("性别不能为空");
        return;
    }
    var birthday = $("#birthday").val();
    if(birthday == ""){
        alert("生日不能为空");
        return;
    }
    var email = $("#email").val();
    if(email == ""){
        alert("邮箱日期不能为空");
        return;
    }
    var phone = $("#phone").val();
    if(phone == ""){
        alert("手机号不能为空");
        return;
    }
    var landline = $("#landline").val();
    if(landline == ""){
        alert("座机号不能为空");
        return;
    }
    var depa = $("#depa").val();
    if(depa == ""){
        alert("部门不能为空");
        return;
    }
	
	var post = $("#post").val();
    if(post == ""){
        alert("人员职务不能为空");
        return;
    }
	
	var organization = $("#organization").val();
    if(organization == ""){
        alert("组织结构不能为空");
        return;
    }
	
	var autograph = $("#autograph").val();
    if(autograph == ""){
        alert("签名不能为空");
        return;
    }
	


    var ajax = new $ax("/user/updateID", function (data) {
        // 成功
        if (data.status == "true") {
            alert("更新成功");
            window.location.href='user.html';
        } else {
            // mui.alert(data.message);
            alert("更新失败");
        }

    }, function (data) {
        // 失败
        alert("访问失败");
        errorAjax();
        alert("更新失败");
    });

    ajax.setToken(cookie.get("token"));
    ajax.set("id",id);
	ajax.set("userName",userName);
	ajax.set("password",password);
    ajax.set("gender",gender);
    ajax.set("birthday",birthday);
    ajax.set("email",email);
    ajax.set("phone",phone);
    ajax.set("landline",landline);
    ajax.set("depa",depa);
	ajax.set("post",post);
	ajax.set("organization",organization);
	ajax.set("autograph",autograph);
    ajax.start();
}

/**
 * 获取指定的URL参数值
 * URL:http://www.xxxxxxx.com/index?name=tyler
 * 参数：paramName URL参数
 * 调用方法:getParam("name")
 * 返回值:tyler
 */
function getParam(paramName) {
    paramValue = "", isFound = !1;
    if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
        arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
        while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
    }
    return paramValue == "" && (paramValue = null), paramValue
}


//return y + '-' + m + '-' + d +' '+h+':'+minute;
function formatDateTimeYMDHM(inputTime) {
    var date = new Date(inputTime);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    // return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
    return y + '-' + m + '-' + d +' '+h+':'+minute;
};